﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using H2.Collections;

namespace HCDV.HCSP
{
    #region 字段类
    public class Field
    {
        private string _name;
        /// <summary>
        /// 名称
        /// </summary>
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        private string _value;
        /// <summary>
        /// 值
        /// </summary>
        public string Value
        {
            get { return _value == null ? null : _value.Replace("'", "''"); }
            set { _value = value; }
        }

        private SqlDbType _type;
        /// <summary>
        /// 数据类型
        /// </summary>
        public SqlDbType Type
        {
            get { return _type; }
            set { _type = value; }
        }
    }

    public class Fields
    {
        private DataList m_datas;

        public Fields()
        {
            m_datas = new DataList();
        }

        public string[] Names
        {
            get { return m_datas.name_list; }
        }

        public int Count
        {
            get { return m_datas.count; }
        }
        public void AddField(string name, string value)
        {
            AddField(name, value, SqlDbType.VarChar);
        }
        public void AddField(string name, string value, SqlDbType type)
        {
            Field field = new Field();
            field.Name = name;
            field.Value = value;
            field.Type = type;

            m_datas.AddData(name, field);
        }

        public void AddField(string name, string value, bool neednull)
        {
            if (value == null) return;
            Field field = new Field();
            field.Name = name;
            field.Value = value;
            field.Type = SqlDbType.VarChar;

            m_datas.AddData(name, field);
        }
        public Field GetField(string name)
        {
            return m_datas.GetData(name) as Field;
        }
    }
    #endregion
}
